<?php
namespace Home\Controller;
use Think\Controller;
class TuijianController extends Controller {
    public function tuijian(){
        $type = I('get.type');
        if($type){
            // 传分类显示的类型
            $this -> assign('type',$type);
            $type -= 1;
            $count = M('tuijian') -> where('type='.$type) -> count();
            $page = new \Think\Page($count,9);
            $page -> rollPage = 3;             //大于3条信息就显示首页和末页
            $page -> lastSuffix = false;       //末页是否显示数字
            $page -> setConfig('prev','上一页');
            $page -> setConfig('next','下一页');
            $page -> setConfig('first','首页');
            $page -> setConfig('last','末页');
            $show = $page -> show();
            $data = M('tuijian') -> where('type='.$type) -> limit($page->firstRow,$page->listRows) -> select();
            $this -> assign('data',$data);
            $this -> assign('show',$show);
            $this -> display();
        }else{
            //分页
            //实例化模型
            $model = M('tuijian');
            //分页第一步：查询总的记录数
            $count = $model -> count();
            //分页第二部：实例化分页类，传递参数
            $page = new \Think\Page($count,6);  //每页显示一个
            //分页第三步（可选）定制分页按钮的提示文字
            $page -> rollPage = 3;             //大于3条信息就显示首页和末页
            $page -> lastSuffix = false;       //末页是否显示数字
            $page -> setConfig('prev','上一页');
            $page -> setConfig('next','下一页');
            $page -> setConfig('first','首页');
            $page -> setConfig('last','末页');
            //分页第四步：使用show方法生成url
            $show = $page -> show();
            //分页第五步：使用limit方法展示数据
            $data = $model -> limit($page->firstRow,$page->listRows) -> select();
            $this -> assign('data',$data);
            $this -> assign('show',$show);
            $this -> display();
        }
    }
    public function tuijianshow(){
        $id = I('get.id');
        $data = M('tuijian') -> find($id);
        $data['tuijian_text']=html_entity_decode( $data['tuijian_text']);
        $this->assign('data',$data);
        // 前一篇
        $id_up = $id - 1;
        $data_up = M('tuijian') -> find($id_up);
        if(empty($data_up)){$data_up['title']="没有了";}
        $this->assign('data_up',$data_up);
        // 后一篇
        $id_down = $id + 1;
        $data_down = M('tuijian') -> find($id_down);
        
        if(empty($data_down)){$data_down['title']="没有了";}
        $this->assign('data_down',$data_down);
        // 相关推荐
        $data_xg = M('tuijian') -> where('id!='.$id.' and type='.$data['type']) -> limit(4) -> select();
        $this->assign('data_xg',$data_xg);
        $this->display();
    }
    public function ajaxdianzan(){
        $get = I('get.id');
        $model = M('fengmian');
        $data = $model->find($get);
        ++$data['hot'];
        $model -> save($data);
        echo json_encode($data);
    }
}